package 结构型模型.装饰器模式;

//抽象构建
public interface ICar {
    void run();
}

//具体构建对象(真实对象)
class Car implements ICar {
    @Override
    public void run() {
        System.out.println("陆地跑");
    }
}

//装饰角色
class SuperCar implements ICar {
    protected ICar car;
    public SuperCar(ICar car) {
        this.car = car;
    }

    @Override
    public void run() {
        car.run();
    }
}


class FlyCar extends SuperCar {

    public FlyCar(ICar car) {
        super(car);
    }

    @Override
    public void run() {
        super.run();
       fly();
    }
    public void fly(){
        System.out.println("天上飞");
    }
}


class WaterCar extends SuperCar {
    public WaterCar(ICar car) {
        super(car);
    }

    @Override
    public void run() {
        super.run();
        water();
    }
    public void water(){
        System.out.println("水里游");
    }
}